package com.gc.cscott.domain.contest.numbers;

import com.google.common.base.Preconditions;

/**
 *
 * @author root
 */
public abstract class AbstractNumber<T extends AbstractNumber> extends Number implements Comparable<T> {
    private final int value;

    public AbstractNumber(int value) {
        Preconditions.checkArgument(value>0,"Number value can not be set less than 1.");
        this.value = value;
    }

    @Override
    public int intValue() {
        return value;
    }

    @Override
    public long longValue() {
        return value;
    }

    @Override
    public float floatValue() {
        return value;
    }

    @Override
    public double doubleValue() {
        return value;
    }

    public int compareTo(T other) {
        return this.intValue()-other.intValue();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final AbstractNumber<T> other = (AbstractNumber<T>) obj;
        if (this.value != other.value) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + this.value;
        return hash;
    }
}
